home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-04-13 | 16.0 KB | 530 lines | [F+PR/FOX+] |
- *-
- *- Demo.PRG
- *-
- *- demonstrate features of PlotGraph XFCN
- *-
- CLEAR PROGRAM
- CLEAR ALL
- SET TALK OFF
- SET BELL OFF
- SET CONFIRM ON
- *-
- *- make this my procedure file
- *-
- SET PROCEDURE TO demo
- *-
- *- open up resource file and load XFCN
- *-
- SET RESOURCE TO plotGraph && open the resource file
- LOAD plotGraph FUNCTION && load up the graph drawing XFCN
- *-
- *- initialize some constants
- *-
- STORE 256 TO mItalic
- STORE 512 TO mBold
- STORE 1024 TO mUnderLine
- *-
- *- initialize variables for options
- *-
- STORE 3 TO mGraphType
- STORE 2 TO mFormat
- STORE LEFT('Times' + SPACE(15),15) TO mGFontNam
- STORE 10 TO mGFontSiz
- STORE 1 TO mGFontSty
- STORE LEFT('Graph Title' + SPACE(40), 40) TO mGTitle
- STORE LEFT('Times' + SPACE(15),15) TO mGTFontNam
- STORE 12 TO mGTFontSiz
- STORE 2 TO mGTFontSty
- STORE '$' TO mCurrSym
- STORE 0 TO mMin
- STORE 0 TO mMax
- STORE 0 TO mFwd, mBack
- STORE 0 TO mEdit, mPlot, mDone
- STORE 0 TO mSteps
- STORE .t. TO mShowXAxis
- STORE .t. TO mShowYAxis
- STORE .t. TO mShowLeg
- STORE .t. TO mShowPct
- STORE .t. TO mAutoScale
- STORE .f. TO mCurrSymPl
- STORE .f. TO mShowXGrid
- STORE .t. TO mShowYGrid
- STORE 125 TO mWidth
- *-
- STORE 10 TO mOTop,mOTopX
- STORE 20 TO mOLeft, mOLeftX
- STORE 280 TO mOBottom,mOBottomX
- STORE 480 TO mORight, mORightX
- *-
- STORE 60 TO mGTop
- STORE 100 TO mGLeft
- STORE 260 TO mGBottom
- STORE 300 TO mGRight
- *-
- *- initialize variables for plotting graph
- *-
- STORE '' TO mData1, mData2 && data to graph
- STORE 0 TO mNumPoints && number of data points on graph, or slices in pie
- STORE '' TO mORect && outer rectangle for graph
- STORE '' TO mGRect && rectangle for graph itself
- STORE '' TO mGOpt && graph options
- STORE '' TO mGFont && font + style for graph legends
- STORE '' TO mGTitl && text, font + style for graph title
- STORE '' TO mXLeg && text for X-axis legends
- STORE 0 TO mGMinMax && minimum and maximum value for line or bar graph, width of legend box for pies
- STORE '' TO mResult && will contain result of XFCN call
- *-
- *- open up data file
- *-
- SELECT 1
- USE sample
- *-
- *- open up data file of labels
- SELECT 2
- USE GLabels
- SELECT sample
- *-
- *- Initialize screens
- *-
- SCREEN 2 OFF
- CLEAR
- SCREEN 2 HEADING "Results of plotGraph" AT 40,40 TYPE 0 SIZE 290,480 PIXELS TOP LOCK
- *-
- STORE 24 TO mleadingx && space between lines
- STORE 16 TO mleft1
- STORE 140 TO mleft2
- STORE 300 TO mleft3
- STORE 300 TO mbottom
- STORE 480 TO mright
- SCREEN 1 OFF
- CLEAR
- SCREEN 1 OFF AT 0,0 HEADING "plotGraph Options" TYPE 0 SIZE mbottom,mright PIXELS FONT 'chicago',12
- *-
- *- display an initial graph (see procedure below)
- *-
- DO pPlotGraph
- *-
- DO WHILE .t.
- STORE 0 TO mFwd, mBack, mEdit, mLabl, mPlot, mDone
- *-
- *- display options portion of screen
- *-
- SCREEN 1 TOP LOCK
- *@ PIXELS 20,mleft1 SAY "Set graph options:"
- *@ PIXELS 25,mleft1 TO 25, mright - mleft1
- STORE 25 TO mx
- *-
- *- Graph heading font etc.
- *-
- @ PIXELS mx, mleft1 SAY "Graph title"
- @ PIXELS mx, mleft2 GET mGTitle FONT 'monaco',12
- STORE mx + mleadingx TO mx
- @ PIXELS mx, mleft1 SAY "Graph title font"
- @ PIXELS mx, mleft2 GET mGTFontNam FONT 'monaco',12
- @ PIXELS mx, 260 SAY "Size"
- @ PIXELS mx, COL(1) + 10 GET mGTFontSiz PICTURE '999' FONT 'monaco',12
- @ PIXELS mx,COL(1) + 15 SAY "Style"
- @ PIXELS mx, COL(1) + 10 GET mGTFontSty PICTURE '@^ Plain;Bold;Italic;Underline' FONT 'chicago',12
- STORE mx + mleadingx TO mx
- *-
- *- Type of graph
- *-
- @ PIXELS mx, mleft1 SAY "Graph type"
- @ PIXELS mx, mleft2 GET mGraphType PICTURE "@*RH Line;Bar;Pie" VALID 1000
- STORE mx + mleadingx TO mx
- *-
- *- Outer rectangle
- *-
- @ PIXELS mx, mleft1 SAY "Outer rectangle"
- @ PIXELS mx,mleft2 SAY "Top"
- @ PIXELS mx, COL(1) + 10 GET mOTop PICTURE '9999' FONT 'monaco',12
- @ PIXELS mx, COL(1) + 15 SAY "Left"
- @ PIXELS mx, COL(1) + 10 GET mOLeft PICTURE '9999' FONT 'monaco',12
- @ PIXELS mx, COL(1) + 15 SAY "Bottom"
- @ PIXELS mx, COL(1) + 10 GET mOBottom PICTURE '9999' FONT 'monaco',12
- @ PIXELS mx, COL(1) + 15 SAY "Right"
- @ PIXELS mx, COL(1) + 10 GET mORight PICTURE '9999' FONT 'monaco',12
- STORE mx + mleadingx TO mx
- *-
- *- Graph rectangle
- *-
- @ PIXELS mx, mleft1 SAY "Graph rectangle"
- @ PIXELS mx, mleft2 SAY "Top"
- @ PIXELS mx, COL(1) + 10 GET mGTop PICTURE '9999' FONT 'monaco',12
- @ PIXELS mx, COL(1) + 15 SAY "Left"
- @ PIXELS mx, COL(1) + 10 GET mGLeft PICTURE '9999' FONT 'monaco',12
- @ PIXELS mx, COL(1) + 15 SAY "Bottom"
- @ PIXELS mx, COL(1) + 10 GET mGBottom PICTURE '9999' FONT 'monaco',12
- @ PIXELS mx, COL(1) + 15 SAY "Right"
- @ PIXELS mx, COL(1) + 10 GET mGRight PICTURE '9999' FONT 'monaco',12
- STORE mx + mleadingx TO mx
- *-
- *- Graph font etc.
- *-
- @ PIXELS mx, mleft1 SAY "Graph font"
- @ PIXELS mx, mleft2 GET mGFontNam FONT 'monaco',12
- @ PIXELS mx, 260 SAY "Size"
- @ PIXELS mx, COL(1) + 10 GET mGFontSiz PICTURE '999' FONT 'monaco',12
- @ PIXELS mx,COL(1) + 15 SAY "Style"
- @ PIXELS mx, COL(1) + 10 GET mGFontSty PICTURE '@^ Plain;Bold;Italic;Underline' FONT 'chicago',12
- STORE mx + mleadingx TO mx
- *-
- *- Format of legends
- *-
- @ PIXELS mx, mleft1 SAY "Legend format"
- @ PIXELS mx, mleft2 GET mFormat PICTURE "@^ General;Currency;Percent" FONT 'chicago',12
- @ PIXELS mx, 250 SAY "Currency symbol"
- @ PIXELS mx, COL(1) + 10 GET mCurrSym PICTURE 'X' FONT 'monaco',12
- @ PIXELS mx, COL(1) + 15 GET mCurrSymPl PICTURE '@*C After'
- STORE mx + mleadingx TO mx
- *-
- *- Scaling
- *-
- IF mGraphType < 3
- @ PIXELS mx, mleft1 GET mAutoScale PICTURE "@*C Auto Scaling" VALID 1000
- ELSE
- *- option isn't avaliable for pies
- @ PIXELS mx, mleft1 SAY mAutoScale PICTURE "@*C Auto Scaling"
- ENDIF
- *-
- @ PIXELS mx, 140 SAY "Start"
- @ PIXELS mx, 250 SAY "End"
- @ PIXELS mx, 360 SAY "Steps"
- IF mGraphType < 3
- IF .NOT. mAutoScale
- @ PIXELS mx, 180 GET mMin PICTURE '99999999' FONT 'monaco', 12
- @ PIXELS mx, 285 GET mMax PICTURE '99999999' FONT 'monaco', 12
- ELSE
- DO p50Screen WITH mx, 140, 12, VAL(SYS(1030,"Start"))
- DO p50Screen WITH mx, 250, 12, VAL(SYS(1030,"End"))
- @ PIXELS mx, 180 SAY mMin PICTURE '99999999' FONT 'monaco', 12
- @ PIXELS mx, 285 SAY mMax PICTURE '99999999' FONT 'monaco', 12
- ENDIF
- @ PIXELS mx, 405 GET mSteps PICTURE '99999999' FONT 'monaco', 12
- ELSE
- *- option isn't avaliable for pies
- DO p50Screen WITH mx, 140, 12, VAL(SYS(1030,"Start"))
- DO p50Screen WITH mx, 250, 12, VAL(SYS(1030,"End"))
- DO p50Screen WITH mx, 350, 12, VAL(SYS(1030,"Number"))
- @ PIXELS mx, 180 SAY mMin PICTURE '99999999' FONT 'monaco', 12
- @ PIXELS mx, 285 SAY mMax PICTURE '99999999' FONT 'monaco', 12
- @ PIXELS mx, 405 SAY mSteps PICTURE '99999999' FONT 'monaco', 12
- ENDIF
- STORE mx + mleadingx TO mx
- *-
- *- X- and Y- axis options
- *-
- @ PIXELS mx, mleft1 SAY 'Show Labels'
- IF mGraphType < 3
- *- line or bar
- @ PIXELS mx, COL(1) + 10 GET mShowXAxis PICTURE "@*C X-Axis"
- @ PIXELS mx, COL(1) + 10 GET mShowYAxis PICTURE "@*C Y-Axis"
- @ PIXELS mx,COL(1) + 15 SAY 'Show Grid'
- @ PIXELS mx, COL(1) + 10 GET mShowXGrid PICTURE "@*C Vert"
- @ PIXELS mx, COL(1) + 10 GET mShowYGrid PICTURE "@*C Horiz"
- ELSE
- @ PIXELS mx, COL(1) + 10 SAY mShowXAxis PICTURE "@*C X-Axis"
- @ PIXELS mx, COL(1) + 10 SAY mShowYAxis PICTURE "@*C Y-Axis"
- @ PIXELS mx,COL(1) + 15 SAY 'Show Grid'
- @ PIXELS mx, COL(1) + 10 SAY mShowXGrid PICTURE "@*C Vert"
- @ PIXELS mx, COL(1) + 10 SAY mShowYGrid PICTURE "@*C Horiz"
- ENDIF
- STORE mx + mleadingx TO mx
- IF mGraphType < 3
- @ PIXELS mx, mleft1 SAY mShowLeg PICTURE "@*C Show Legends"
- @ PIXELS mx, 175 SAY mShowPct PICTURE "@*C Show %ages"
- @ PIXELS mx, 330 SAY "Box width"
- DO p50Screen WITH mx, 330, 12, VAL(SYS(1030,"Box width"))
- @ PIXELS mx, 405 SAY mWidth PICTURE '999' FONT 'monaco',12
- ELSE
- @ PIXELS mx, mleft1 GET mShowLeg PICTURE "@*C Show Legends"
- @ PIXELS mx, 175 GET mShowPct PICTURE "@*C Show %ages"
- @ PIXELS mx, 330 SAY "Box width"
- @ PIXELS mx, 405 GET mWidth PICTURE '999' FONT 'monaco',12
- ENDIF
- STORE mx + mleadingx TO mx
- *-
- *- Display controls for this dialog
- @ PIXELS mbottom - 41, 22 SAY mBack PICTURE "@* \I1001"
- IF .NOT. BOF() .AND. RECNO() > 1
- @ PIXELS mbottom - 41, 22 GET mBack PICTURE "@* \I1001" VALID 1000
- ELSE
- *- gray out
- DO p50Screen WITH mbottom - 9,22, 32, 32
- ENDIF
- @ PIXELS mbottom - 35, 60 GET mEdit PICTURE "@* Edit Data" SIZE 20,85 STYLE 1 VALID 1000
- @ PIXELS mbottom - 35, 150 GET mLabl PICTURE "@* Labels" SIZE 20,85 STYLE 1 VALID 1000
- @ PIXELS mbottom - 35, 240 GET mPlot PICTURE "@* Plot It" SIZE 20,85 STYLE 1 VALID 1000
- @ PIXELS mbottom - 35, 330 GET mDone PICTURE "@* Done" SIZE 20,85 STYLE 1 VALID 1000
- @ PIXELS mbottom - 41, 421 SAY mFwd PICTURE "@* \I1002"
- IF .NOT. EOF() .AND. RECNO() < RECC()
- @ PIXELS mbottom - 41, 421 GET mFwd PICTURE "@* \I1002" VALID 1000
- ELSE
- *- gray out
- DO p50Screen WITH mbottom - 9, 421, 32, 32
- ENDIF
- READ
- *
- *- process action
- *-
- IF mDone = 1
- *- done
- EXIT
- ENDIF
- IF mEdit = 1
- *- edit data
- EDIT
- ENDIF
- IF mLabl = 1
- *- edit label data
- SELECT gLabels
- EDIT
- SELECT sample
- ENDIF
- IF mPlot = 1
- *-
- *- display a graph (see procedure below)
- *-
- DO pPlotGraph
- ENDIF
- IF mBack = 1 .AND. RECNO() > 1
- SKIP -1
- DO pPlotGraph
- ENDIF
- IF mFwd = 1 .AND. RECNO() < RECC()
- SKIP
- DO pPlotGraph
- ENDIF
- *- loop back around and display new graph
- ENDDO
- *- cleanup and leave
- RELEASE MODULE plotGraph
- SET RESOURCE TO
- CLOSE DATABASE
- SCREEN 1 TOP SIZE mbottom, mright PIXELS HEADING "Screen 1" FONT 'chicago', 12
- CLEAR
- SCREEN 2 DELETE
- RETURN
- *- end of main program
-
- *-
- *- PROCEDURE pPlotGraph
- *-
- *- takes care of plotting out data from the current record
- *- of SAMPLE.DBF
- *-
- *- use globals defined in main program above
- *-
- PROCEDURE pPlotGraph
- *-
- *- display a graph
- *-
- IF mGraphType = 1 .OR. mGraphType = 2
- *-
- *- line or bar graph
- *-
- *-
- *- 1. set number of points to graph
- *-
- STORE 12 TO mNumPoints
- *-
- *- 2. load up data strings
- *-
- STORE STR(sample->period1,10) + ;
- STR(sample->period2,10) + ;
- STR(sample->period3,10) + ;
- STR(sample->period4,10) + ;
- STR(sample->period5,10) TO mData1
- STORE mdata1 + ;
- STR(sample->period6,10) + ;
- STR(sample->period7,10) + ;
- STR(sample->period8,10) + ;
- STR(sample->period9,10) + ;
- STR(sample->period10,10) TO mData1
- STORE mdata1 + ;
- STR(sample->period11,10) + ;
- STR(sample->period12,10) TO mData1
- *-
- *- 3. define outer rectangle for graph + legends + title
- *-
- STORE STR(mOLeft,5) + ;
- STR(mOTop,5) + ;
- STR(mORight,5) + ;
- STR(mOBottom,5) to mORect
- *-
- *- 4. define inner rectangle for graph itself
- *-
- STORE STR(mGLeft,5) + ;
- STR(mGTop,5) + ;
- STR(mGRight,5) + ;
- STR(mGBottom,5) to mGRect
- *-
- *- 5. set graph options
- *-
- STORE IIF(mGraphType = 1, 'L', 'B') + ;
- SUBSTR('G$%', mFormat, 1) + ;
- IIF(mShowXAxis, 'Y', 'N') + ;
- IIF(mShowYAxis, 'Y', 'N') + ;
- mCurrSym + ;
- IIF(mCurrSymPl,'A','B') + ;
- IIF(mAutoScale,'A','F') TO mGOpt
- STORE mGOpt + ;
- IIF( mShowXGrid, 'Y','N') + ;
- IIF( mShowYGrid, 'Y','N') TO mGOpt
- *-
- *- 6. set font, size and style for graph legends
- *-
- STORE TRIM(mGFontNam) + ';' + ;
- LTRIM(STR(mGFontSiz + IIF(mGFontSty = 1, 0, 2 ^ (6 + mGFontSty)),5)) TO mGFont && Graph font: font; size + style (used for labels)
- *-
- *- 7. set graph title, font, size and style
- *-
- STORE TRIM(mGTitle) + ';' + ;
- TRIM(mGTFontNam) + ';' + ;
- LTRIM(STR(mGTFontSiz + IIF(mGTFontSty = 1, 0, 2 ^ (6 + mGTFontSty)),5)) to mGTitl && Graph title: title; font; size + style
- *-
- *- 8. set values for Legend box
- *-
- STORE GLabels->x1 + ;
- GLabels->x2 + ;
- GLabels->x3 + ;
- GLabels->x4 + ;
- GLabels->x5 + ;
- GLabels->x6 + ;
- GLabels->x7 + ;
- GLabels->x8 + ;
- GLabels->x9 + ;
- GLabels->x10 + ;
- GLabels->x11 + ;
- GLabels->x12 TO mXLeg
- *-
- *- 9. set min and max
- *-
- STORE STR(IIF(mAutoScale, 0, mMin),10) + STR(IIF(mAutoScale, 0, mMax),10) + STR(mSteps,10) to mGMinMax
- ELSE
- *-
- *- pie chart
- *-
- *-
- *- 1. set number of points to graph
- *-
- STORE 5 TO mNumPoints
- *-
- *- 2. load up data strings
- *-
- STORE STR(sample->hardware,10) + ;
- STR(sample->software,10) + ;
- STR(sample->program,10) + ;
- STR(sample->techsupp,10) + ;
- STR(sample->consult,10) TO mData1
- *-
- *- 3. define outer rectangle for graph + legends + title
- *-
- STORE STR(mOLeft,5) + ;
- STR(mOTop,5) + ;
- STR(mORight,5) + ;
- STR(mOBottom,5) to mORect
- *-
- *- 4. define inner rectangle for graph itself
- *-
- STORE STR(mGLeft,5) + ;
- STR(mGTop,5) + ;
- STR(mGRight,5) + ;
- STR(mGBottom,5) to mGRect
- *-
- *-
- *- 5. set graph options
- *-
- STORE 'P' + ;
- SUBSTR('G$%', mFormat, 1) + ;
- IIF(mShowLeg, 'Y', 'N') + ;
- IIF(mShowPct, 'Y', 'N') + ;
- mCurrSym + ;
- IIF(mCurrSymPl,'A','B') + ;
- 'F' + ' ' TO mGOpt
- *-
- *- 6. set font, size and style for graph legends
- *-
- STORE TRIM(mGFontNam) + ';' + ;
- LTRIM(STR(mGFontSiz + IIF(mGFontSty = 1, 0, 2 ^ (6 + mGFontSty)),5)) TO mGFont && Graph font: font; size + style (used for labels)
- *-
- *- 7. set graph title, font, size and style
- *-
- STORE TRIM(mGTitle) + ';' + ;
- TRIM(mGTFontNam) + ';' + ;
- LTRIM(STR(mGTFontSiz + IIF(mGTFontSty = 1, 0, 2 ^ (6 + mGTFontSty)),5)) to mGTitl && Graph title: title; font; size + style
- *-
- *- 8. set values for X-Axis legend
- *-
- STORE GLabels->Slice1 + ;
- GLabels->Slice2 + ;
- GLabels->Slice3 + ;
- GLabels->Slice4 + ;
- GLabels->Slice5 TO mXLeg
- *-
- *- 9. set maximum value for graph, or 0 if auto-scaling
- *-
- STORE mWidth to mGMinMax
- ENDIF && which graph type
- *-
- *- At last, call the XFCN
- *-
- SCREEN 2 LOCK
- IF mORight <> mORightX .OR. mOLeft <> mOLeftX .OR. mOBottom <> mOBottomX .OR. mOTop <> mOTopX
- *- outer rectangle changed, so clear area, just in case
- CLEAR
- *- and remember new values
- STORE mORight TO mORightX
- STORE mOLeft TO mOLeftX
- STORE mOBottom TO mOBottomX
- STORE mOTop TO mOTopX
- ENDIF
- CALL plotGraph TO mResult WITH mNumPoints, mData1, mData2 , mORect, mGRect, mGOpt, mGFont, mGTitl, mXLeg, mGMinMax
- *-
- *- may have been an error in paramters, so check
- *-
- *- "0" = no error
- *- "1" = wrong number of parameters was passed
- *- "2" = grect extends beyond orect, or pie chart and grect isn't square
- IF VAL(mresult) > 0
- DO CASE
- CASE mresult = "1"
- STORE "Wrong number of parameters" TO merror
- CASE mresult = "2"
- STORE "Graph rectangle must be completely within outer rectangle" TO merror
- CASE mresult = "3"
- STORE "Graph rectangle must be square for pie graphs" TO merror
- CASE mresult = "4"
- STORE "Too many data points — max is 10 for a pie chart, 50 for line and bar graphs" TO merror
- OTHERWISE
- STORE "Unknown error" TO merror
- ENDCASE
- ALERT NOTE 8 "Error calling plotGraph: " + merror + ". (" + mresult + ")"
- ELSE
- *- save graph as picture, for later printing
- SAVE SCREEN TO aGraph AT mOTop,mOLeft SIZE mOBottom - mOTop, mORight - mOLeft PIXELS
- IF mGraphType < 3
- *- line or bar
- REPLACE saleGraph WITH aGraph
- ELSE
- REPLACE mixGraph WITH aGraph
- ENDIF
- ENDIF
- SCREEN 1 LOCK TOP
- RETURN
- *- eop pPlotGraph
-
- *-
- *- PROCEDURE pScreen
- *-
- * ' 50% screen on rectangle (mx - mh,my to mx + 3,my + mw + 3)
- *-
- PROCEDURE p50Screen
- PARAMETERS mrow, mcol, mheight, mwid
- *-
- @ PIXELS mrow - mheight,mcol TO mrow + 3,mcol + mwid + 3 STYLE 198664
- RETURN
- *- eop p50Screen
-
- *- end of Demo.PRG
-